package com.ruoyi.erp.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.erp.domain.BankAccountTransfer;
import com.ruoyi.erp.service.IBankAccountTransferService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 账户间往来Controller
 * 
 * @author sauger
 * @date 2022-04-01
 */
@Controller
@RequestMapping("/erp/transfer")
public class BankAccountTransferController extends BaseController
{
    private String prefix = "erp/transfer";

    @Autowired
    private IBankAccountTransferService bankAccountTransferService;

    @RequiresPermissions("erp:bank:transfer:view")
    @GetMapping()
    public String transfer()
    {
        return prefix + "/transfer";
    }

    /**
     * 查询账户间往来列表
     */
    @RequiresPermissions("erp:bank:transfer:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BankAccountTransfer bankAccountTransfer)
    {
        startPage();
        List<BankAccountTransfer> list = bankAccountTransferService.selectBankAccountTransferList(bankAccountTransfer);
        return getDataTable(list);
    }

    /**
     * 导出账户间往来列表
     */
    @RequiresPermissions("erp:bank:transfer:export")
    @Log(title = "账户间往来", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BankAccountTransfer bankAccountTransfer)
    {
        List<BankAccountTransfer> list = bankAccountTransferService.selectBankAccountTransferList(bankAccountTransfer);
        ExcelUtil<BankAccountTransfer> util = new ExcelUtil<BankAccountTransfer>(BankAccountTransfer.class);
        return util.exportExcel(list, "账户间往来数据");
    }

    /**
     * 新增账户间往来
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存账户间往来
     */
    @RequiresPermissions("erp:bank:transfer:add")
    @Log(title = "账户间往来", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BankAccountTransfer bankAccountTransfer)
    {
        bankAccountTransfer.setCreateBy(this.getSysUser().getUserName());
        return toAjax(bankAccountTransferService.insertBankAccountTransfer(bankAccountTransfer));
    }

    /**
     * 修改账户间往来
     */
    @RequiresPermissions("erp:bank:transfer:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
        BankAccountTransfer bankAccountTransfer = bankAccountTransferService.selectBankAccountTransferById(id);
        mmap.put("bankAccountTransfer", bankAccountTransfer);
        return prefix + "/edit";
    }

    /**
     * 修改保存账户间往来
     */
    @RequiresPermissions("erp:bank:transfer:edit")
    @Log(title = "账户间往来", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BankAccountTransfer bankAccountTransfer)
    {
        return toAjax(bankAccountTransferService.updateBankAccountTransfer(bankAccountTransfer));
    }

    /**
     * 删除账户间往来
     */
    @RequiresPermissions("erp:bank:transfer:remove")
    @Log(title = "账户间往来", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(bankAccountTransferService.deleteBankAccountTransferByIds(ids));
    }
}
